home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / sun4c.md / devEmulexTape.c < prev    next >
C/C++ Source or Header  |  1991-08-11  |  4KB  |  128 lines

  1. /* 
  2.  * devEmulexTape.c --
  3.  *
  4.  *      Procedures that set up command blocks and process sense
  5.  *    data for Emulex tape drives.
  6.  *
  7.  * Copyright 1986 Regents of the University of California
  8.  * All rights reserved.
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: /sprite/src/kernel/dev/sun3.md/RCS/devEmulexTape.c,v 9.0 89/09/12 14:58:53 douglis Stable $ SPRITE (Berkeley)";
  20. #endif not lint
  21.  
  22.  
  23. #include "sprite.h"
  24. #include "dev.h"
  25. #include "devInt.h"
  26. #include "scsi.h"
  27. #include "scsiDevice.h"
  28. #include "scsiHBA.h"
  29. #include "scsiTape.h"
  30. #include "emulexTape.h"
  31.  
  32. /*
  33.  * Sense data returned from the Emulex tape controller in the shoeboxes.
  34.  */
  35. #define EMULEX_SENSE_BYTES    11
  36. typedef struct {
  37.     ScsiClass7Sense    extSense;    /* 8 Bytes */
  38.     unsigned char pad1        :1;
  39.     unsigned char error        :7;    /* Regular SCSI error code */
  40.     unsigned char highRetries;        /* High byte of retry count */
  41.     unsigned char lowRetries;        /* Low byte of retry count */
  42. } EmulexTapeSense;            /* Known to be 11 Bytes big */
  43.  
  44.  
  45. /*
  46.  * Definitions for the mode select command.  This is specific to the
  47.  * Emulex controller.  The mode select command is used to change from
  48.  * QIC_24 format (one standard, not the one we use) to QIC_02 format
  49.  * (the more common, older, standard that we do use).
  50.  */
  51.  
  52. typedef struct EmulexModeSelBlock {
  53.     unsigned char density;        /* Density code */
  54.     unsigned char highCount;        /* Count of blocks at this density */
  55.     unsigned char midCount;        /*    middle byte of above */
  56.     unsigned char lowCount;        /*    low byte */
  57.     unsigned char pad1;            /* Reserved */
  58.     unsigned char highLength;        /* Length of the blocks */
  59.     unsigned char midLength;        /*    middle byte of above */
  60.     unsigned char lowLength;        /*    low byte */
  61. } EmulexModeSelBlock;
  62.  
  63. /*
  64.  * Density values for the mode select block.
  65.  */
  66. #define EMULEX_QIC_24    0x05
  67. #define EMULEX_QIC_02    0x84
  68.  
  69. typedef struct EmulexModeSelParams {
  70.     ScsiTapeModeSelectHdr    header;
  71.     EmulexModeSelBlock    block;
  72.     unsigned char        :5;    /* Reserved */
  73.     unsigned char disableErase    :1;    /* disable erase ahead */
  74.     unsigned char autoLoadInhibit :1;
  75.     unsigned char softErrorCount  :1;
  76. } EmulexModeSelParams;
  77.  
  78.  
  79. /*
  80.  *----------------------------------------------------------------------
  81.  *
  82.  * DevEmulexAttach --
  83.  *
  84.  *    Verify and initialize the attached scsi device as a emulex tape..
  85.  *
  86.  * Results:
  87.  *    SUCCESS if the device is a working emulex tape drive.
  88.  *    DEV_NO_DEVICE if the device is not a emulex tape drive.
  89.  *    A Sprite return status if the device is a broken emulex tape drive.
  90.  *
  91.  * Side effects:
  92.  *    Sets the type and call-back procedures.
  93.  *
  94.  *----------------------------------------------------------------------
  95.  */
  96. /*ARGSUSED*/
  97. ReturnStatus
  98. DevEmulexAttach(devicePtr, devPtr, tapePtr)
  99.     Fs_Device    *devicePtr;    /* Fs_Device being attached. */
  100.     ScsiDevice    *devPtr;    /* SCSI device handle for drive. */
  101.     ScsiTape    *tapePtr;    /* Tape drive state to be filled in. */
  102. {
  103.     unsigned char statusByte;
  104.     ScsiCmd    senseCmd;
  105.     char    senseData[SCSI_MAX_SENSE_LEN];
  106.     int        length;
  107.     ReturnStatus    status;
  108.     /*
  109.      * Since we don't know about the inquiry data (if any) returned by 
  110.      * the Emulex tape, check using the size of the SENSE data returned.
  111.      */
  112.     DevScsiSenseCmd(devPtr, SCSI_MAX_SENSE_LEN, senseData, &senseCmd);
  113.     status = DevScsiSendCmdSync(devPtr, &senseCmd, &statusByte, &length,
  114.                   (int *) NIL, (char *) NIL);
  115.     if ( (status != SUCCESS) || 
  116.          (statusByte != 0) ||
  117.      ((length != EMULEX_SENSE_BYTES) &&
  118.       (length != SCSI_MAX_SENSE_LEN) &&
  119.       (length != 14)) ){
  120.     return DEV_NO_DEVICE;
  121.     }
  122.     /*
  123.      * Take all the defaults for the tapePtr.
  124.      */
  125.     tapePtr->name = "Emulex Tape";
  126.     return SUCCESS;
  127. }
  128.